SET(TARGET_NAME PluginXml)
#PROJECT(${TARGET_NAME})
#必须要有的宏定义
ADD_DEFINITIONS (-DPLUGIN_XML_EXPORT)


IF(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
ENDIF()

#使用gl3
#ADD_DEFINITIONS(-DOSG_GL3_AVAILABLE)

#INCLUDE_DIRECTORIES("..\\..\\include")
#LINK_DIRECTORIES("..\\..\\lib")
IF (CMAKE_CL_64)
ELSE()
ENDIF()
	# INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/${TARGET_NAME}/include)
	INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/${TARGET_NAME})
	INCLUDE_DIRECTORIES( ${PROJECT_BINARY_DIR}/${TARGET_NAME})#为了ui生成的头文件
    INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/LibUiQt)
    INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/LibCommon)

    # INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/Lib3dXML)
    # INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/LibVrep)
	LINK_DIRECTORIES( ${PROJECT_BINARY_DIR}/lib)
	

    INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR})
	INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR}/QtCore)
	INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR}/QtWidgets)
    INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR}/QtGui)
    INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR}/QtXml)
    INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR}/QtOpenGL)
	link_directories(${QT_LIB_DIR})
	
    # INCLUDE_DIRECTORIES(${RTTR_INCLUDE_DIR})
    # LINK_DIRECTORIES(${RTTR_LIB_DIR})

    INCLUDE_DIRECTORIES( ${QT_TABTOOLBAR_INCLUDE_DIR})
    LINK_DIRECTORIES( ${QT_TABTOOLBAR_LIB_DIR} )

find_package(Qt5Widgets)
ADD_DEFINITIONS (${Qt5Widgets_DEFINITIONS})
    # INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR})
    # INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR}/QtCore)
	# link_directories(${QT_LIB_DIR})
	#INCLUDE_DIRECTORIES( ${QT_DIR}/include)
	#INCLUDE_DIRECTORIES( ${QT_DIR}/include/QtCore)
	#LINK_DIRECTORIES( ${QT_DIR}/lib)
#库文件在debug下名字后面加d
SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING "add a postfix, usually d on windows")
SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
#ADD_DEFINITIONS (${Qt5Widgets_DEFINITIONS})

FILE(GLOB_RECURSE ThisTarget_INCLUDE_LIST "${PROJECT_SOURCE_DIR}/${TARGET_NAME}/*.h")
FILE(GLOB_RECURSE ThisTarget_SRC_LIST "${PROJECT_SOURCE_DIR}/${TARGET_NAME}/*.cpp")

FILE(GLOB QTDEMO_UI_LIST "${PROJECT_SOURCE_DIR}/${TARGET_NAME}/*.ui")
FILE(GLOB QTDEMO_RESOURCE_LIST "${PROJECT_SOURCE_DIR}/${TARGET_NAME}/*.qrc")

source_group("include" FILES ${ThisTarget_INCLUDE_LIST})
source_group("src" FILES ${ThisTarget_SRC_LIST})
source_group("ui" FILES ${QTDEMO_UI_LIST})
source_group("resource" FILES ${QTDEMO_RESOURCE_LIST})

qt5_wrap_cpp(example_MOCS 	${ThisTarget_INCLUDE_LIST})
QT5_WRAP_UI(example_UIS ${QTDEMO_UI_LIST} )#OPTIONS("uic -help")
qt5_add_resources(example_RCC_SRCS ${QTDEMO_RESOURCE_LIST} )#OPTIONS("rcc -help")
source_group("generated_file" FILES ${example_MOCS} ${example_UIS} ${example_RCC_SRCS} )

ADD_LIBRARY(${TARGET_NAME} 
    SHARED 
    ${ThisTarget_SRC_LIST} 
    ${ThisTarget_INCLUDE_LIST} 
    ${example_MOCS}  
    ${example_UIS}  
    ${example_RCC_SRCS} 
    ${QTDEMO_UI_LIST} 
    ${QTDEMO_RESOURCE_LIST}  )#${example_MOCS_Share}

IF (UNIX)
SET(ADDITIONAL_LIBRARIES_RELEASE
        Qt5Widgets
        Qt5Core
        Qt5Gui
        Qt5Xml
        LibCommon
        LibUiQt
        TabToolbar
)

SET(ADDITIONAL_LIBRARIES_DEBUG
        Qt5Widgets
        Qt5Core
        Qt5Gui
        Qt5Xml
        LibCommon
        LibUiQt
        TabToolbar
)
ELSEIF(WIN32)
SET(ADDITIONAL_LIBRARIES_RELEASE
        Qt5Widgets
        Qt5Core
        Qt5Gui
        Qt5Xml
        LibCommon
        LibUiQt
        TabToolbar
)

SET(ADDITIONAL_LIBRARIES_DEBUG
        Qt5Widgetsd
        Qt5Cored
        Qt5Guid
        Qt5Xmld
        LibCommond
        LibUiQtd
        TabToolbard
)
ENDIF()


TARGET_LINK_LIBRARIES(${TARGET_NAME} PRIVATE debug "${ADDITIONAL_LIBRARIES_DEBUG}" PRIVATE optimized "${ADDITIONAL_LIBRARIES_RELEASE}")
set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin/plugin)
set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin/plugin)
set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/bin/plugin)

#set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:CONSOLE /ENTRY:mainCRTStartup")# WINDOWS

set_target_properties(${TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib)
set_target_properties(${TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/lib)

set(ExeReflectionPath ${PROJECT_BINARY_DIR}/ExeReflection.exe)


#增加生成反射代码的命令

#第一种，通过生成bat文件然后再调用它
# set(OUTPUT_CMD_FILE ${CMAKE_CURRENT_BINARY_DIR}/reflectionCommand_autogen.bat)

# add_custom_command( 
    # PRE_BUILD 
    # OUTPUT ${OUTPUT_CMD_FILE}
    # COMMAND ${CMAKE_COMMAND} -E echo "${PROJECT_BINARY_DIR}/bin/ExeReflection.exe -f ${ThisTarget_INCLUDE_LIST} -i ${PROJECT_SOURCE_DIR}/PluginXml;${PROJECT_SOURCE_DIR}/LibUiQt;${PROJECT_SOURCE_DIR}/LibCommon -o ${PROJECT_SOURCE_DIR}/PluginXml/Autogen " > ${OUTPUT_CMD_FILE}
    # COMMENT "Generating reflectionCommand_autogen.bat for ${TARGET_NAME}"
# ) 
# add_custom_target(generate_header ALL DEPENDS ${OUTPUT_CMD_FILE}) 

# add_custom_command(TARGET ${TARGET_NAME} 
    # POST_BUILD 
    # COMMAND  ${OUTPUT_CMD_FILE} || true
# ) 

#第二种，直接再CMake中调用ExeReflection
#注意这里搜索exe的路径是从${CMAKE_CURRENT_BINARY_DIR}路径开始的，也就是
#D:/eric/coding/EEditor2/source/build_vs2019_x64/PluginXml
#再windows下，需要加上最后的两个小标记：> nul 2>&1
#第一个是将标准输出重定向到nul，第二个是将stderror输出重定向给标准输出。整体会屏蔽所有的输出。
#这样可以避免vs检测到错误从而停止整个生成过程。
# set(REFLECTION_H 
    # "${PROJECT_SOURCE_DIR}/PluginXml/EItemXmlRoot.h"
    # "${PROJECT_SOURCE_DIR}/PluginXml/ItemBaseXml.h"
    # )

# IF(WIN32)
# add_custom_command(TARGET ${TARGET_NAME} 
    # PRE_BUILD 
    # COMMAND ../bin/ExeReflection.exe 
    # -f "${REFLECTION_H}"
        # -i "${PROJECT_SOURCE_DIR}/PluginXml;${PROJECT_SOURCE_DIR}/LibUiQt;${PROJECT_SOURCE_DIR}/LibCommon"
        # -o "${PROJECT_SOURCE_DIR}/PluginXml/Autogen"
        # > nul 2>&1
# ) 
# ELSE()
# add_custom_command(TARGET ${TARGET_NAME} 
    # PRE_BUILD 
    # COMMAND ../bin/ExeReflection
    # -f "${REFLECTION_H}"
        # -i "${PROJECT_SOURCE_DIR}/PluginXml;${PROJECT_SOURCE_DIR}/LibUiQt;${PROJECT_SOURCE_DIR}/LibCommon"
        # -o "${PROJECT_SOURCE_DIR}/PluginXml/Autogen"
# ) 
# ENDIF()

# add_custom_command(TARGET ${TARGET_NAME} 
    # PRE_BUILD 
    # COMMAND echo HELLO
# ) 
